/**
 * Project Name:HomeActivity
 * Date:2016-1-26下午5:52:37
 * Copyright (c) 2016, askzhao All Rights Reserved.
 *
 */
package com.kkd.kkdapp.adapter;

import java.text.DecimalFormat;
import java.util.List;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.activity.ForTenderActivity;
import com.kkd.kkdapp.activity.CreditParticularsActivity;
import com.kkd.kkdapp.activity.EveryDayParticularsActivity;
import com.kkd.kkdapp.activity.EveryDayTenderActivity;
import com.kkd.kkdapp.activity.ForTenderActivity;
import com.kkd.kkdapp.activity.KKDWebActivity;
import com.kkd.kkdapp.activity.LoginActivity;
import com.kkd.kkdapp.activity.ParticularsActivity;
import com.kkd.kkdapp.activity.TenderAffirmActivity;
import com.kkd.kkdapp.http.entity.BannerTwoItem;
import com.kkd.kkdapp.http.entity.HomeRecommend;
import com.kkd.kkdapp.http.entity.HomeRecommendList;
import com.kkd.kkdapp.http.entity.HomeTender;
import com.kkd.kkdapp.utils.LogUtil;
import com.kkd.kkdapp.utils.PreferenceUtils;
import com.kkd.kkdapp.utils.SystemUtils;
import com.kkd.kkdapp.view.PolygonView;
import com.kkd.kkdapp.view.RoundTextView;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.OvershootInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * ClassName: CardAdapter <br/>
 * date: 2016-1-26 下午5:52:37 <br/>
 * 
 * @author askzhao
 * @version
 */
public class CardAdapter extends BaseAdapter {

	private static final int LABLE_ITEM_TYPE_RECOMMEND = 0;
	private static final int LABLE_ITEM_TYPE_NOTICE = 1;
	public static final int LABLE_ITEM_POSITION_RECOMMEND = 0;
	public static final int RECOMMEND_LIST_ITEM_SIZE = 1;
	public static final int RECOMMEND_POSITION_NOTICE = RECOMMEND_LIST_ITEM_SIZE + 1;
	public static final int LABLE_ITEM_POSITION_NOTICE = RECOMMEND_LIST_ITEM_SIZE + 3;
	LayoutInflater mLayoutInflater;
	// public int[] mData;
	private TranslateAnimation animation;
	private Context mContext;
	private List<HomeRecommend> activities; // 公告
	private List<HomeTender> bidList; // 推荐标
	private List<BannerTwoItem> bannerTwo;// 新手区标的
	private List<HomeRecommendList> recommendList;
	private DecimalFormat df = new DecimalFormat("0.00");
	private int recommendType;
	private double balance;

	private View view1;
	private View view2;
	private Intent intent;

	/**
	 * @param homeactivity
	 * @param activities
	 * @param bidList
	 * @param recommendList
	 * @param bannerTwo
	 */
	public CardAdapter(Context context, List<HomeRecommend> activities,
			List<HomeTender> bidList, List<HomeRecommendList> recommendList,
			List<BannerTwoItem> bannerTwo) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(mContext);
		this.activities = activities;
		this.bidList = bidList;
		this.recommendList = recommendList;
		this.bannerTwo = bannerTwo;
		// mData = imgs;
		animation = new TranslateAnimation(0, SystemUtils.dip2px(mContext, 15),
				0, 0);
		animation.setInterpolator(new OvershootInterpolator(8f));
		animation.setDuration(1000);
		animation.setRepeatCount(1);
		animation.setRepeatMode(Animation.REVERSE);
		view1 = LayoutInflater.from(mContext).inflate(R.layout.list_item_lable,
				null);
		view2 = LayoutInflater.from(mContext).inflate(R.layout.list_item_lable,
				null);

	}

	@Override
	public int getCount() {

		int count = 0;
		if (bannerTwo.size() > 0)
			count++;
		if (activities.size() > 0)
			count += activities.size() + 1;
		if (recommendList.size() > 0) {
			count += 2;
		}
		return count;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (bannerTwo.size() > 0) {

			if (position == 0) {
				return getPromptItemView(position, convertView, parent);
			} else if (position == 1) { // 1
				return getLableItemView(LABLE_ITEM_TYPE_RECOMMEND, position,
						convertView, parent);
			} else if (position == 2) { // 2
				return getRecommendItemView(position, convertView, parent);
			} else if (position == 3) { // 3
				return getLableItemView(LABLE_ITEM_TYPE_NOTICE, position,
						convertView, parent);
			} else {
				return getNoticeItemView(position, convertView, parent);
			}

		} else {
			if (position == 0) { // 0
				return getLableItemView(LABLE_ITEM_TYPE_RECOMMEND, position,
						convertView, parent);
			} else if (position == 1) { // 1

				return getRecommendItemView(position, convertView, parent);

			} else if (position == 2) { // 2

				return getLableItemView(LABLE_ITEM_TYPE_NOTICE, position,
						convertView, parent);

			} else {

				return getNoticeItemView(position, convertView, parent);

			}
		}

	}

	private View getPromptItemView(final int position, View convertView,
			ViewGroup parent) {
		PromptViewHolder holder;

		if (convertView != null
				&& convertView.getTag() instanceof PromptViewHolder) {
			holder = (PromptViewHolder) convertView.getTag();
		} else {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.homefragment_one_item, null);
			holder = new PromptViewHolder();
			holder.sign_type = (RoundTextView) convertView
					.findViewById(R.id.sign_type);
			holder.content_tv = (TextView) convertView
					.findViewById(R.id.content_tv);
			holder.interest_tv = (TextView) convertView
					.findViewById(R.id.interest_tv);
			holder.term_tv = (TextView) convertView.findViewById(R.id.term_tv);
			holder.term_company = (TextView) convertView
					.findViewById(R.id.term_company);
			holder.tiyan_sign_type = (RoundTextView) convertView
					.findViewById(R.id.tiyan_sign_type);
			holder.tiyan_content = (TextView) convertView
					.findViewById(R.id.tiyan_content);
			holder.tiyan_interest_tv = (TextView) convertView
					.findViewById(R.id.tiyan_interest_tv);
			holder.tiyan_term_tv = (TextView) convertView
					.findViewById(R.id.tiyan_term_tv);
			holder.tiyan_term_company = (TextView) convertView
					.findViewById(R.id.tiyan_term_company);
			holder.novice_ll = (LinearLayout) convertView
					.findViewById(R.id.novice_ll);
			holder.tiyan_ll = (LinearLayout) convertView
					.findViewById(R.id.tiyan_ll);
			holder.interest_company = (TextView) convertView
					.findViewById(R.id.interest_company);
			holder.up_img1 = (ImageView) convertView.findViewById(R.id.up_img1);
			holder.up_img = (ImageView) convertView.findViewById(R.id.up_img);
			convertView.setTag(holder);
		}
		/************************ 新手专享 *******************/
		// 标题
		holder.sign_type.setRoundBackground(Color.parseColor(bannerTwo.get(0)
				.getColor()));
		holder.sign_type.setText(bannerTwo.get(0).getTitle());
		// 内容
		holder.content_tv.setText(bannerTwo.get(0).getContent());
		// 利率
		holder.interest_tv.setText(bannerTwo.get(0).getInterest());

		LogUtil.e("Color", bannerTwo.get(0).getColor() + "");

		LogUtil.e("Color", Color.parseColor(bannerTwo.get(0).getColor()) + "");

		holder.interest_tv.setTextColor(Color.parseColor(bannerTwo.get(0)
				.getColor()));

		holder.interest_company.setTextColor(Color.parseColor(bannerTwo.get(0)
				.getColor()));
		// 期限
		holder.term_tv.setTextColor(Color.parseColor(bannerTwo.get(0)
				.getColor()));
		holder.term_tv.setText(bannerTwo.get(0).getPeriod() + "");
		// 期限单位
		holder.term_company.setTextColor(Color.parseColor(bannerTwo.get(0)
				.getColor()));
		String periodType = bannerTwo.get(0).getPeriodType();
		holder.term_company.setText(periodType);
		holder.novice_ll.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String bidId = bannerTwo.get(0).getBidId();
				int productType = bannerTwo.get(0).getProductType();
				if (productType == 3) {
					intent = new Intent(mContext,
							CreditParticularsActivity.class);
					intent.putExtra("bidId", bidId);
					mContext.startActivity(intent);
				} else {
					intent = new Intent(mContext, ParticularsActivity.class);
					intent.putExtra("bidId", bidId);
					mContext.startActivity(intent);
				}
			}
		});
		holder.novice_ll.setOnTouchListener(new MyOnTouch(holder.up_img1));
		/*********************** 特权本金专享 *********************/
		// 标题
		holder.tiyan_sign_type.setRoundBackground(Color.parseColor(bannerTwo
				.get(1).getColor()));
		holder.tiyan_sign_type.setText(bannerTwo.get(1).getTitle());
		// 内容
		holder.tiyan_content.setText(bannerTwo.get(1).getContent());
		// 利率
		holder.tiyan_interest_tv.setText(bannerTwo.get(1).getInterest());
		holder.tiyan_interest_tv.setTextColor(Color.parseColor(bannerTwo.get(1)
				.getColor()));
		// 期限
		holder.tiyan_term_tv.setTextColor(Color.parseColor(bannerTwo.get(1)
				.getColor()));
		holder.tiyan_term_tv.setText(bannerTwo.get(1).getPeriod() + "");
		// 期限单位
		holder.tiyan_term_company.setText(bannerTwo.get(1).getPeriod() + "");
		String tiyan_periodType = bannerTwo.get(1).getPeriodType();
		holder.tiyan_term_company.setText(tiyan_periodType);
		holder.tiyan_ll.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String bidId = bannerTwo.get(1).getBidId();
				int productType = bannerTwo.get(1).getProductType();
				if (productType == 3) {
					intent = new Intent(mContext,
							CreditParticularsActivity.class);
					intent.putExtra("bidId", bidId);
					mContext.startActivity(intent);
				} else {
					intent = new Intent(mContext, ParticularsActivity.class);
					intent.putExtra("bidId", bidId);
					mContext.startActivity(intent);
				}
			}
		});
		holder.tiyan_ll.setOnTouchListener(new MyOnTouch(holder.up_img));
		return convertView;
	}

	private class PromptViewHolder {
		RoundTextView sign_type;
		RoundTextView tiyan_sign_type;
		TextView content_tv;
		TextView interest_tv;
		TextView term_tv;
		TextView term_company;
		TextView tiyan_content;
		TextView tiyan_interest_tv;
		TextView tiyan_term_tv;
		TextView tiyan_term_company;
		LinearLayout novice_ll, tiyan_ll;
		TextView interest_company;
		ImageView up_img1, up_img;
	}

	private View getLableItemView(int type, int position, View convertView,
			ViewGroup parent) {

		if (type == LABLE_ITEM_TYPE_RECOMMEND) {
			ImageView mLableIcon = (ImageView) view1
					.findViewById(R.id.lable_icon);
			TextView mLableText = (TextView) view1
					.findViewById(R.id.lable_text);
			mLableIcon.setImageResource(R.drawable.home_icon_recommend);
			mLableText.setText(mContext.getString(R.string.lable_recommend));
			view1.startAnimation(animation);
			return view1;
		} else if (type == LABLE_ITEM_TYPE_NOTICE) {
			ImageView mLableIcon = (ImageView) view2
					.findViewById(R.id.lable_icon);
			TextView mLableText = (TextView) view2
					.findViewById(R.id.lable_text);
			mLableIcon.setImageResource(R.drawable.home_icon_notice);
			mLableText.setText(mContext.getString(R.string.lable_notice));
			view2.startAnimation(animation);
			return view2;
		}
		return null;
	}

	private View getRecommendItemView(int position, View convertView,
			ViewGroup parent) {
		RecommendItemViewHolder holder;
		if (convertView != null
				&& convertView.getTag() instanceof RecommendItemViewHolder) {
			holder = (RecommendItemViewHolder) convertView.getTag();
		} else {
			holder = new RecommendItemViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.list_item_recommend, null);
			holder.notice_top = (LinearLayout) convertView
					.findViewById(R.id.notice_top);
			holder.bid = (TextView) convertView.findViewById(R.id.bid);
			holder.down_img = (ImageView) convertView
					.findViewById(R.id.down_img);
			convertView.setTag(holder);
		}

		if (recommendList.size() > 0) {
			recommendType = recommendList.get(0).getRecommendType();
		}
		if (recommendType == 1) {
			// 标题
			holder.recommend_title = (TextView) convertView
					.findViewById(R.id.recommend_title);
			holder.recommend_title.setText(recommendList.get(0).getData()
					.getTitle());
			// 标类型
			holder.tender_ico = (PolygonView) convertView.findViewById(R.id.pv);
			holder.tender_ico.setText("天天赚");
			holder.tender_ico.setBackgroundResource(R.drawable.home_y);
			// 利率
			holder.recommend_interest_price = (TextView) convertView
					.findViewById(R.id.recommend_interest_price);

			holder.recommend_interest_price.setText(recommendList.get(0)
					.getData().getInterestDisplay());
			// 标的总额
			holder.recommend_rental = (TextView) convertView
					.findViewById(R.id.recommend_rental);
			holder.recommend_rental.setText("开放额度（元）");
			String bidAmount = df.format(recommendList.get(0).getData()
					.getAmount() * 0.01);
			holder.recommend_rental_price = (TextView) convertView
					.findViewById(R.id.recommend_rental_price);
			holder.recommend_rental_price.setText(bidAmount);
			// 期限
			holder.recommend_deadline = (TextView) convertView
					.findViewById(R.id.recommend_deadline);
			holder.recommend_deadline.setText("剩余额度（元）");
			holder.recommend_deadline_price = (TextView) convertView
					.findViewById(R.id.recommend_deadline_price);
			String freeAmount = df.format((recommendList.get(0).getData()
					.getAmount() - recommendList.get(0).getData()
					.getBuyFreeAmountSum()) * 0.01);
			holder.recommend_deadline_price.setText(freeAmount);
			holder.notice_top.setOnClickListener(new TenderOnclick(
					recommendList.get(0).getData().getYuebaoId(), recommendList
							.get(0).getData().getTitle(), freeAmount, bidList
							.get(0).getLowestAmount(), bidList.get(0)
							.getAmountMultiple(), bidList.get(0)
							.getBidPeriodType(), bidList.get(0)
							.getInterestDisplay(), bidList.get(0)
							.getBidFreeAmount(), bidList.get(0)
							.getMaxAmountDisplay(), bidList.get(0)
							.getBidAmount(), bidList.get(0).getTotalLixi(), 0));
			holder.bid.setText("认购");
			LogUtil.e("YuebaoId", recommendList.get(0).getData().getYuebaoId());
			holder.bid.setOnClickListener(new TenderOnclick(recommendList
					.get(0).getData().getYuebaoId(), recommendList.get(0)
					.getData().getTitle(), freeAmount, bidList.get(0)
					.getLowestAmount(), bidList.get(0).getAmountMultiple(),
					bidList.get(0).getBidPeriodType(), bidList.get(0)
							.getInterestDisplay(), bidList.get(0)
							.getBidFreeAmount(), bidList.get(0)
							.getMaxAmountDisplay(), bidList.get(0)
							.getBidAmount(), bidList.get(0).getTotalLixi(), 0));
		} else if (recommendType == 2) {
			// 标题
			holder.recommend_title = (TextView) convertView
					.findViewById(R.id.recommend_title);
			holder.recommend_title.setText(bidList.get(0).getBidTitle());

			// 标类型
			holder.tender_ico = (PolygonView) convertView.findViewById(R.id.pv);
			int w = SystemUtils.dip2px(mContext, 53);
			int ts = SystemUtils.dip2px(mContext, 10);
			int h = (int) (ts * 1.5);
			int tx = (w - ts * bidList.get(0).getBidTypeName2().length()) / 2;
			int ty = (int) (ts * 1.25);
			holder.tender_ico.setXY(0, 0, w, 0, w, h, w / 2, ts * 2, 0, h);
			holder.tender_ico.setTextSize(ts);
			holder.tender_ico.setTextXY(tx, ty);

			holder.tender_ico.setText(bidList.get(0).getBidTypeName2());
			holder.tender_ico.setBackground(Color.parseColor(bidList.get(0)
					.getBidTypeColor2()));
			// 利率
			holder.recommend_interest_price = (TextView) convertView
					.findViewById(R.id.recommend_interest_price);
			holder.recommend_interest_tv = (TextView) convertView
					.findViewById(R.id.recommend_interest_tv);
			// bidList.get(0).getInterestDisplay()
			if (bidList.get(0).getInterestDisplay().length() > 5) {
				holder.recommend_interest_tv.setPadding(0, 20, 0, 0);
				holder.recommend_interest_price.setPadding(0, 18, 0, 0);
				holder.recommend_interest_price.setTextSize(22);
			} else {
				holder.recommend_interest_tv.setPadding(0, 0, 0, 0);
				holder.recommend_interest_price.setPadding(0, 0, 0, 0);
				holder.recommend_interest_price.setTextSize(34);
			}
			holder.recommend_interest_price.setText(bidList.get(0)
					.getInterestDisplay());
			// 标的总额
			holder.recommend_rental_price = (TextView) convertView
					.findViewById(R.id.recommend_rental_price);
			holder.recommend_rental_price.setText(""
					+ bidList.get(0).getBidAmount() / 100);

			// 期限
			holder.recommend_deadline_price = (TextView) convertView
					.findViewById(R.id.recommend_deadline_price);
			holder.recommend_deadline_price.setText(bidList.get(0)
					.getBidPeriod() + "");
			holder.recommend_deadline = (TextView) convertView
					.findViewById(R.id.recommend_deadline);
			holder.recommend_deadline.setText("还款期限（"
					+ bidList.get(0).getBidPeriodType() + "）");
			holder.notice_top.setOnClickListener(new TenderOnclick(bidList.get(
					0).getBidId(), bidList.get(0).getBidTitle(), bidList.get(0)
					.getBidPeriod() + "", bidList.get(0).getLowestAmount(),
					bidList.get(0).getAmountMultiple(), bidList.get(0)
							.getBidPeriodType(), bidList.get(0)
							.getInterestDisplay(), bidList.get(0)
							.getBidFreeAmount(), bidList.get(0)
							.getMaxAmountDisplay(), bidList.get(0)
							.getBidAmount(), bidList.get(0).getTotalLixi(),
					bidList.get(0).getProductType()));
			holder.bid.setOnClickListener(new TenderOnclick(bidList.get(0)
					.getBidId(), bidList.get(0).getBidTitle(), bidList.get(0)
					.getBidPeriod() + "", bidList.get(0).getLowestAmount(),
					bidList.get(0).getAmountMultiple(), bidList.get(0)
							.getBidPeriodType(), bidList.get(0)
							.getInterestDisplay(), bidList.get(0)
							.getBidFreeAmount(), bidList.get(0)
							.getMaxAmountDisplay(), bidList.get(0)
							.getBidAmount(), bidList.get(0).getTotalLixi(),
					bidList.get(0).getProductType()));
		}
		holder.notice_top.setOnTouchListener(new MyOnTouch(holder.down_img));
		return convertView;
	}

	private View getNoticeItemView(final int position, View convertView,
			ViewGroup parent) {
		NoticeItemViewHolder holder;

		if (convertView != null
				&& convertView.getTag() instanceof NoticeItemViewHolder) {
			holder = (NoticeItemViewHolder) convertView.getTag();
			holder.mImageView.setImageResource(R.drawable.home_ad);
		} else {
			holder = new NoticeItemViewHolder();
			convertView = mLayoutInflater
					.inflate(R.layout.home_list_item, null);
			holder.mImageView = (ImageView) convertView
					.findViewById(R.id.image);
			holder.down_image = (ImageView) convertView
					.findViewById(R.id.down_img);
			convertView.setTag(holder);
		}

		if (bannerTwo != null && bannerTwo.size() > 0) {

			ImageLoader.getInstance().displayImage(
					activities.get(position - 4).getImage(), holder.mImageView,
					R.drawable.home_ad);

		} else {

			ImageLoader.getInstance().displayImage(
					activities.get(position - 3).getImage(), holder.mImageView,
					R.drawable.home_ad);

		}

		holder.mImageView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (bannerTwo != null) {

					if (bannerTwo.size() > 0) {

						if (position > 3) {
							if (!TextUtils.isEmpty(activities.get(position - 4)
									.getUrl())) {
								Intent intent = new Intent(mContext,
										KKDWebActivity.class);
								intent.putExtra("titleName",
										activities.get(position - 4).getTitle());
								intent.putExtra("desc",
										activities.get(position - 4).getDesc());
								String url = activities.get(position - 4)
										.getUrl();
								intent.putExtra("url",
										activities.get(position - 4).getUrl());
								intent.putExtra("shareUrl",
										activities.get(position - 4)
												.getShareUrl());
								mContext.startActivity(intent);
							}
						}

					} else if (bannerTwo.size() == 0) {

						if (position > 2) {
							Intent intent = new Intent(mContext,
									KKDWebActivity.class);
							intent.putExtra("titleName",
									activities.get(position - 3).getTitle());
							String url = activities.get(position - 3).getUrl();
							intent.putExtra("url", activities.get(position - 3)
									.getUrl());
							intent.putExtra("shareUrl",
									activities.get(position - 3).getShareUrl());
							mContext.startActivity(intent);

						}

					}

				} else {

					if (position > 2) {
						Intent intent = new Intent(mContext,
								KKDWebActivity.class);
						intent.putExtra("titleName",
								activities.get(position - 3).getTitle());
						String url = activities.get(position - 3).getUrl();
						intent.putExtra("url", activities.get(position - 3)
								.getUrl());
						intent.putExtra("shareUrl", activities
								.get(position - 3).getShareUrl());
						mContext.startActivity(intent);

					}

				}

			}
		});
		holder.mImageView.setOnTouchListener(new MyOnTouch(holder.down_image));
		return convertView;
	}

	private class LableItemViewHolder {
		public ImageView mLableIcon;
		public TextView mLableText;
	}

	private class RecommendItemViewHolder {
		public TextView recommend_title; // 标题
		public TextView recommend_interest_price; // 年利率
		public TextView recommend_rental_price; // 标的总额
		public TextView recommend_rental;
		public TextView recommend_deadline_price; // 期限
		public TextView recommend_deadline;
		public PolygonView tender_ico; // 标的类型
		public LinearLayout notice_top; // 标详情
		public TextView bid; // 投标
		public RelativeLayout recom_rl;
		public TextView recommend_interest_tv;
		ImageView down_img;
	}

	private class NoticeItemViewHolder {
		public ImageView mImageView, down_image;
	}

	private class TenderOnclick implements OnClickListener {
		private Intent intent;
		private String bidId;
		private String bidTitle;
		private String bidPeriod;
		private long amountMultiple; // 倍数
		private long lowestAmount; // 最小金额
		private String bidPeriodType; // 期限单位
		private String bidInterest;
		private long bidFreeAmount;
		private String maxAmount;
		private long bidAmount;
		private long totalLixi;
		private int productType;

		public TenderOnclick(String bidId, String bidTitle, String bidPeriod,
				long amountMultiple, long lowestAmount, String bidPeriodType,
				String bidInterest, long bidFreeAmount, String maxAmount,
				long bidAmount, long totalLixi, int productType) {
			this.bidId = bidId;
			this.bidTitle = bidTitle;
			this.bidPeriod = bidPeriod;
			this.amountMultiple = amountMultiple;
			this.lowestAmount = lowestAmount;
			this.bidPeriodType = bidPeriodType;
			this.bidInterest = bidInterest;
			this.bidFreeAmount = bidFreeAmount;
			this.maxAmount = maxAmount;
			this.bidAmount = bidAmount;
			this.totalLixi = totalLixi;
			this.productType = productType;
		}

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.bid:
				LogUtil.e("YuebaoId", bidId);
				if (PreferenceUtils.getInstance().getLogin(mContext) == 0) { // 登陆验证

					if (PreferenceUtils.getInstance().getAutonym(mContext) == 1) { // 身份认证

						if (PreferenceUtils.getInstance().getBoundBankCard(
								mContext) == 1) { // 判定银行卡是否绑定
							if (recommendType == 1) { // 天天赚
								intent = new Intent(mContext,
										EveryDayTenderActivity.class);
								intent.putExtra("title", bidTitle);
								intent.putExtra("surplus", bidPeriod);
								intent.putExtra("yuebaoid", bidId);
								mContext.startActivity(intent);
							} else if (recommendType == 2) { // 定期宝，房宝宝
								if (productType == 3) {
									intent = new Intent(mContext,
											TenderAffirmActivity.class);
									intent.putExtra("bidId", bidId);
									intent.putExtra("bidTitle", bidTitle);
									intent.putExtra("bidPeriod",
											Integer.parseInt(bidPeriod));
									intent.putExtra("amountMultiple",
											amountMultiple);
									intent.putExtra("lowestAmount",
											lowestAmount);
									intent.putExtra("bidPeriodType",
											bidPeriodType);
									intent.putExtra("bidInterest", bidInterest);
									intent.putExtra("bidFreeAmount",
											bidFreeAmount);
									intent.putExtra("maxAmount", maxAmount);
									intent.putExtra("bidAmount", bidAmount);
									intent.putExtra("totalLixi", totalLixi);
									intent.putExtra("businessType", "3");
									mContext.startActivity(intent);
								} else {
									intent = new Intent(mContext,
											TenderAffirmActivity.class);
									intent.putExtra("bidId", bidId);
									intent.putExtra("bidTitle", bidTitle);
									intent.putExtra("bidPeriod",
											Integer.parseInt(bidPeriod));
									intent.putExtra("amountMultiple",
											amountMultiple);
									intent.putExtra("lowestAmount",
											lowestAmount);
									intent.putExtra("bidPeriodType",
											bidPeriodType);
									intent.putExtra("bidInterest", bidInterest);
									intent.putExtra("bidFreeAmount",
											bidFreeAmount);
									intent.putExtra("maxAmount", maxAmount);
									intent.putExtra("bidAmount", bidAmount);
									intent.putExtra("totalLixi", totalLixi);
									intent.putExtra("businessType", "1");
									mContext.startActivity(intent);
								}
							}
						} else {
							if (balance == 0) {
								if (recommendType == 1) {
									intent = new Intent(mContext,
											ForTenderActivity.class);
									intent.putExtra("enterTypeFlag", 4);
									intent.putExtra("title", bidTitle);
									intent.putExtra("surplus", bidPeriod);
									intent.putExtra("yuebaoid", bidId);
									mContext.startActivity(intent);
								} else if (recommendType == 2) {
									if (productType == 3) {
										intent = new Intent(mContext,
												ForTenderActivity.class);
										intent.putExtra("enterTypeFlag", 5);
										intent.putExtra("bidId", bidId);
										intent.putExtra("bidTitle", bidTitle);
										intent.putExtra("bidPeriod",
												Integer.parseInt(bidPeriod));
										intent.putExtra("amountMultiple",
												amountMultiple);
										intent.putExtra("lowestAmount",
												lowestAmount);
										intent.putExtra("bidPeriodType",
												bidPeriodType);
										intent.putExtra("bidInterest",
												bidInterest);
										intent.putExtra("bidFreeAmount",
												bidFreeAmount);
										intent.putExtra("maxAmount", maxAmount);
										intent.putExtra("bidAmount", bidAmount);
										intent.putExtra("totalLixi", totalLixi);
										intent.putExtra("businessType", "3");
										mContext.startActivity(intent);
									} else {
										intent = new Intent(mContext,
												ForTenderActivity.class);
										intent.putExtra("enterTypeFlag", 5);
										intent.putExtra("bidId", bidId);
										intent.putExtra("bidTitle", bidTitle);
										intent.putExtra("bidPeriod",
												Integer.parseInt(bidPeriod));
										intent.putExtra("amountMultiple",
												amountMultiple);
										intent.putExtra("lowestAmount",
												lowestAmount);
										intent.putExtra("bidPeriodType",
												bidPeriodType);
										intent.putExtra("bidInterest",
												bidInterest);
										intent.putExtra("bidFreeAmount",
												bidFreeAmount);
										intent.putExtra("maxAmount", maxAmount);
										intent.putExtra("bidAmount", bidAmount);
										intent.putExtra("totalLixi", totalLixi);
										intent.putExtra("businessType", "1");
										mContext.startActivity(intent);
									}
								}
							} else {
								if (recommendType == 1) {
									intent = new Intent(mContext,
											EveryDayTenderActivity.class);
									intent.putExtra("title", bidTitle);
									intent.putExtra("surplus", bidPeriod);
									intent.putExtra("yuebaoid", bidId);
									mContext.startActivity(intent);
								} else if (recommendType == 2) {
									if (productType == 3) {
										intent = new Intent(mContext,
												TenderAffirmActivity.class);
										intent.putExtra("bidId", bidId);
										intent.putExtra("bidTitle", bidTitle);
										intent.putExtra("bidPeriod",
												Integer.parseInt(bidPeriod));
										intent.putExtra("amountMultiple",
												amountMultiple);
										intent.putExtra("lowestAmount",
												lowestAmount);
										intent.putExtra("bidPeriodType",
												bidPeriodType);
										intent.putExtra("bidInterest",
												bidInterest);
										intent.putExtra("bidFreeAmount",
												bidFreeAmount);
										intent.putExtra("maxAmount", maxAmount);
										intent.putExtra("bidAmount", bidAmount);
										intent.putExtra("totalLixi", totalLixi);
										intent.putExtra("businessType", "3");
										mContext.startActivity(intent);
									} else {
										intent = new Intent(mContext,
												TenderAffirmActivity.class);
										intent.putExtra("bidId", bidId);
										intent.putExtra("bidTitle", bidTitle);
										intent.putExtra("bidPeriod",
												Integer.parseInt(bidPeriod));
										intent.putExtra("amountMultiple",
												amountMultiple);
										intent.putExtra("lowestAmount",
												lowestAmount);
										intent.putExtra("bidPeriodType",
												bidPeriodType);
										intent.putExtra("bidInterest",
												bidInterest);
										intent.putExtra("bidFreeAmount",
												bidFreeAmount);
										intent.putExtra("maxAmount", maxAmount);
										intent.putExtra("bidAmount", bidAmount);
										intent.putExtra("totalLixi", totalLixi);
										intent.putExtra("businessType", "1");
										mContext.startActivity(intent);
									}
								}

							}

						}

					} else {
						if (recommendType == 1) {
							intent = new Intent(mContext,
									ForTenderActivity.class);
							intent.putExtra("enterTypeFlag", 4);
							intent.putExtra("title", bidTitle);
							intent.putExtra("surplus", bidPeriod);
							intent.putExtra("yuebaoid", bidId);
							mContext.startActivity(intent);

						} else if (recommendType == 2) {
							if (productType == 3) {
								intent = new Intent(mContext,
										ForTenderActivity.class);
								intent.putExtra("enterTypeFlag", 5);
								intent.putExtra("bidId", bidId);
								intent.putExtra("bidTitle", bidTitle);
								intent.putExtra("bidPeriod",
										Integer.parseInt(bidPeriod));
								intent.putExtra("amountMultiple",
										amountMultiple);
								intent.putExtra("lowestAmount", lowestAmount);
								intent.putExtra("bidPeriodType", bidPeriodType);
								intent.putExtra("bidFreeAmount", bidFreeAmount);
								intent.putExtra("bidInterest", bidInterest);
								intent.putExtra("maxAmount", maxAmount);
								intent.putExtra("bidAmount", bidAmount);
								intent.putExtra("totalLixi", totalLixi);
								intent.putExtra("businessType", "3");
								mContext.startActivity(intent);
							} else {
								intent = new Intent(mContext,
										ForTenderActivity.class);
								intent.putExtra("enterTypeFlag", 5);
								intent.putExtra("bidId", bidId);
								intent.putExtra("bidTitle", bidTitle);
								intent.putExtra("bidPeriod",
										Integer.parseInt(bidPeriod));
								intent.putExtra("amountMultiple",
										amountMultiple);
								intent.putExtra("lowestAmount", lowestAmount);
								intent.putExtra("bidPeriodType", bidPeriodType);
								intent.putExtra("bidFreeAmount", bidFreeAmount);
								intent.putExtra("bidInterest", bidInterest);
								intent.putExtra("maxAmount", maxAmount);
								intent.putExtra("bidAmount", bidAmount);
								intent.putExtra("totalLixi", totalLixi);
								intent.putExtra("businessType", "1");
								mContext.startActivity(intent);
							}
						}
					}

				} else {

					intent = new Intent(mContext, LoginActivity.class);
					mContext.startActivity(intent);

				}
				break;
			case R.id.notice_top:
				if (recommendType == 1) {
					intent = new Intent(mContext,
							EveryDayParticularsActivity.class);
					String surplus = df.format((recommendList.get(0).getData()
							.getAmount() - recommendList.get(0).getData()
							.getBuyFreeAmountSum()) * 0.01);
					intent.putExtra("surplus", surplus);
					intent.putExtra("title", recommendList.get(0).getData()
							.getTitle());
					String damount = df.format(recommendList.get(0).getData()
							.getAmount() * 0.01);
					intent.putExtra("amount", damount);
					String interests = df.format(recommendList.get(0).getData()
							.getInterest() * 0.01);
					intent.putExtra("interests", interests);
					intent.putExtra("bmout", recommendList.get(0).getData()
							.getBidProgress());
					int Progressbmout = (int) ((double) recommendList.get(0)
							.getData().getBuyFreeAmountSum()
							/ recommendList.get(0).getData().getAmount() * 100);
					intent.putExtra("Progressbmout", Progressbmout);
					intent.putExtra("buyNumSum", recommendList.get(0).getData()
							.getBuyNumSum());
					intent.putExtra("yuebaoid", bidId);
					mContext.startActivity(intent);
				} else if (recommendType == 2) {
					if (productType == 3) {
						intent = new Intent(mContext,
								CreditParticularsActivity.class);
						intent.putExtra("bidId", bidId);
						mContext.startActivity(intent);
					} else {
						intent = new Intent(mContext, ParticularsActivity.class);
						intent.putExtra("bidId", bidId);
						mContext.startActivity(intent);
					}
				}

				break;
			}

		}
	}

	/**
	 * updateBalance:(这里用一句话描述这个方法的作用). <br/>
	 * 
	 * @author askzhao
	 * @param balance2
	 */
	public void updateBalance(double balance) {
		this.balance = balance;
	}

	class MyOnTouch implements OnTouchListener {

		ImageView img;

		public MyOnTouch(ImageView img) {
			this.img = img;
		}

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			switch (event.getAction()) {

			case MotionEvent.ACTION_DOWN: // 按下
				img.setVisibility(View.VISIBLE);
				break;

			case MotionEvent.ACTION_UP: // 抬起
			case MotionEvent.ACTION_OUTSIDE:
			case MotionEvent.ACTION_CANCEL:

				img.setVisibility(View.GONE);

				break;

			}
			return false;
		}
	}

}
